﻿using System.Collections.Generic;
using DevExpress.Data;
using DevExpress.Utils;
using WindowsForms.AOnline.Presenter.Dictionary.FixedAsset;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlFixedAssetList : BaseListUserControl, IFixedAssetsView  
    {
        private readonly FixedAssetsPresenter _fixedAssetPresenter;   

        public UserControlFixedAssetList()
        {
            InitializeComponent();
            _fixedAssetPresenter = new FixedAssetsPresenter(this);
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
            return new FixedAssetPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {
            TotalPage = _fixedAssetPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _fixedAssetPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.FixedAssetModel> FixedAssets
        {
            set
            {
                ListBindingSource.DataSource = value;
                gridView.PopulateColumns(value);

                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetCode", ColumnCaption = "Mã tài sản", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetName", ColumnCaption = "Tên tài sản", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 350 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "OrgPrice", ColumnCaption = "Nguyên giá", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 100, ColumnType = UnboundColumnType.Decimal });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UsedDate", ColumnCaption = "Ngày sử dụng", ColumnPosition = 4, ColumnVisible = true, ColumnWith = 100, ColumnType = UnboundColumnType.DateTime, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "State", ColumnCaption = "Tình trạng", ColumnPosition = 5, ColumnVisible = true, ColumnWith = 100,  Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetForeignName", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "ProductionYear", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "MadeIn", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetCategoryId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "PurchasedDate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepreciationDate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IncrementDate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DisposedDate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Unit", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "SerialNumber", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Accessories", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Quantity", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitPrice", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccumDepreciationAmount", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "RemainingAmount", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "LifeTime", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepreciationRate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "OrgPriceAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepreciationAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "CapitalAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepartmentId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "EmployeeId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "ExpenseAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "CapitalMoneyAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnVisible = false });
            }
        }
    }
}
